\documentclass[11pt]{beamer}
\usepackage{geometry}                % See geometry.pdf to learn the layout options. There are lots.
               % ... or a4paper or a5paper or ... 
%\geometry{landscape}                % Activate for for rotated page geometry
%\usepackage[parfill]{parskip}    % Activate to begin paragraphs with an empty line rather than an indent
\usepackage{graphicx}
\usepackage{amssymb}
\usepackage{epstopdf}
\usepackage{gb4e}
\usepackage{color}


\usepackage{qtree}
\usepackage{beamerthemesplit}
\usepackage{tipa}
%\usetheme{Frankfurt}
\usepackage{remreset}
\makeatletter
\@removefromreset{subsection}{section}
\makeatother
%\setcounter{subsection}{1}


\DeclareGraphicsRule{.tif}{png}{.png}{`convert #1 `dirname #1`/`basename #1 .tif`.png}

\title{Building OT Grammars in PyPhon}
\subtitle{A Tutorial for the Stanford P-Interest Workshop}
\author{Sam Bowman}
%\date{}                                           % Activate to display a given date or no date

\begin{document}
\maketitle
%\section{}
%\subsection{}

\frame{
\frametitle{What PyPhon is}
\begin{itemize}
\item<1-> PyPhon is a Python Toolkit for constraint based grammars (OT and HG) with a rudimentary command-line interface to build grammars and typologies.
\item Primarily the work of Jason Riggle and Max Bane at the [University of] Chicago Language Modeling Lab. (I've recently been somewhat involved.)

\item<2-> \textbf{The Grand Vision:} \normalsize To enable phonologists to quickly develop large-scale constraint-based grammars in a way that is \textit{guaranteed} to be:
\begin{itemize}
\item Accurate (no erroneous tableaux)
\item Precise (all constraints and feature values clearly described)
\item Monster-free (the typological predictions of a model---including quantitative and implicational generalizations---are immediately visible)
\end{itemize}
 \end{itemize}
}


\frame{
\frametitle{What PyPhon Can Do}
To quote the documentation, PyPhon currently offers the following functionality:
\begin{itemize}
\item<1-> State your model as a set of hand-crafted tableaux, or simply specify your constraints as regular expressions (finite-state acceptors), and let full tableaux be computed automatically for any input forms.
\item<2-> Tableaux candidates can be generated for either OT or HG.
\item<3-> Produce finite state diagrams of your regular constraints.
\item<4-> Generate optima and/or typologies in both OT and HG, optionally subject to grammatical restrictions that can be specified in a variety of ways:
\begin{itemize}
\item As stratified hierarchies (OT)
\item As partial orders (OT)
\item As sets of elementary ranking conditions (OT)
\item As sets of weight assignments and/or inequalities (HG)
\end{itemize}
... \end{itemize}

}


\frame{
\frametitle{What PyPhon Can Do}
...
\begin{itemize}
\item<1-> Count the number of rankings (OT), or volume of weightings (HG), that generate each output form.
\item<2-> Compute typological implications (T-Orders; after Anttila and Andrus 2006) and render pretty graphs.
\item<3-> Create and search typologies in cyclic OT and two-tiered LPM-OT (after Kiparsky, 2000).
 \end{itemize}
}

\frame{
\frametitle{The Alternatives (corrections welcome)}
\begin{itemize}
\item All three can calculate typologies for both ranked or weighted constraints.

\item<2-> OT-Help 2 (UMass team, including Chris Potts): 

\begin{itemize}
\item Well documented; great for finding ranking conditions.
\item Does Harmonic Serialism as well as OT/HG.
\item Automatically finds contenders only for Harmonic Serialism, not OT/HG; requires the user to specify the operations in \textsc{Gen}.
 \end{itemize}

\item<3-> OTSoft 2 (Hayes; UCLA):
\begin{itemize}
\item More explicitly designed to facilitate grammar development: Clearly notes redundant constraints and harmonically bounded (impossible) candidates.
\item Generates T-orders and Hasse diagrams.
\item Written in a dead, Windows-only,  software framework (VB6). Likely moribund.
 \end{itemize}

 \end{itemize}
}


\frame{
\frametitle{Working with Finite-State Constraints}
\begin{itemize}
\item A constraint is represented as a set of regular expressions which \textit{accept} (match) any local input--output mappings that violate it.
\item PyPhon has its own regular expression syntax, which includes special symbols for context, for insertion/deletion and for correspondence with input forms.
\item No comprehensive documentation: Look to example files. (Or ask me!)
 \end{itemize}



}


\frame{
\frametitle{Working with Finite-State Constraints}


\small

\textsc{MaxV}:\\
\texttt{\_[-cons]:-\_} \\\ \\


\textsc{IO-Ident[high]}:\\
\texttt{\_[+high]:[-high]\_} \\
\texttt{\_[-high]:[+high]\_}\\\ \\

\textsc{*NV_{oral}}:\\
\texttt{[+nasal]\_[-cons, -nasal]\_}\\\ \\

\textsc{*P-Shaped}:\\
\texttt{\_(b|p|d|q)\_} \\\ \\

\textsc{*CC\&DepC}:\\
\texttt{C\_-:C\_}\\
\texttt{\_-:C\_C}

}

\frame{
\frametitle{Working with Finite-State Constraints}
\begin{itemize}

\item<1-> Local markedness and faithfulness constraints of all sorts are easy to write and fast to run
\item<2-> Complex long-distance markedness constraints and non-local constraint conjunction are possible, but tend to be somewhat unwieldy, and can cause explosive growth in run time.
\item<3-> Constraints which can accrue violations faster than linearly in the length of the string \textit{cannot} be represented. This includes the already theoretically tenuous \textsc{Align(foot, wd)}.
 \end{itemize}
}


\frame{
\frametitle{In Practice: PyPhon File Types}
\begin{itemize}
\item<1-> \textbf{Inputs file} (\texttt{.csv}): A list of input forms, in your representation of choice, one per line, with comments marked with \texttt{\#}

\item<2-> \textbf{Model description file} (\texttt{.csv}): A file specifying (1) the feature bundles associated with which segments in your representation and (2) the regular expressions that define your constraints.

\item<3-> Model file (\texttt{.mod}): A non-human-readable representation of \textsc{Gen} and \textsc{Eval}, generated from your model description file by \texttt{makemodel}.

\item<4-> Grammar file (\texttt{.csv}): A set of stipulations about the rankings or weightings of your model's constraints.

\item<5-> \textbf{Tableaux file} (\texttt{.csv}): A set of unranked tableaux specifying all of the contenders for each input, and all of their constraint violation profiles.
 \end{itemize}
}

\frame{
\frametitle{In Practice: PyPhon File Types}

\begin{itemize}
\item<1-> Acceptor graph file (\texttt{.dot}): A graph file containing a finite-state acceptor representation of a single constraint or of all of \textsc{Eval}. Used for both visualization and caching. Editable in a pinch.

\item<2-> T-order file (\texttt{.dot}): A graph file representing implicational relationships between input-output mappings.

\item<3-> Typology file (\texttt{.csv}): Shows the possible languages corresponding to a set of tableaux and their corresponding ERCs and R-volumes. 

\item<4-> (!) Input-output file (\texttt{.csv}): Used to test for the existence of a language, as specified by a set of input-output pairs. 

\item<4-> (!) Two tier languages file (.csv): Similar to a typology file, only with less information, and corresponding to a stratal grammar.

 \end{itemize}
}


 

\frame{
\frametitle{In Practice: The Scripts}
\begin{itemize}
\item<1-> \texttt{pyphon\_makemodel.py}: Compiles a model description file into a model file. Optionally also generates acceptor graphs.
\item<2-> \texttt{pyphon\_maketableaux.py}: Takes a model file, an inputs file, and a grammar option (OT or HG), and generates full tableaux for each input.
\item<3-> \texttt{pyphon\_generate.py}: Takes a tableaux file, a grammar option (OT or HG) and optionally a grammar file, and generates typologies and T-orders.

\item<4-> \texttt{pyphon\_twotier.py}: Takes a model file and an inputs file, and generates tableaux and typologies for two-tiered (word and postlexical) LPM-OT.

\end{itemize}
}


\frame{
\frametitle{Installing PyPhon}
\begin{itemize}
\item Get a copy of the source package (as a ZIP or over Subversion) from: \small \url{http://code.google.com/p/clml/}
\item \texttt{cd} into the \texttt{pyphon} directory and run:\\\small
\texttt{python setup.py install}
\item Optional: For HG typologies, get GLPK (link from the CLML site).

\end{itemize}
}



 

\frame{
\frametitle{Writing Inputs and Constraints}
(switch to the software itself)
}


\frame{
\frametitle{Tips, in lieu of complete documentation}
\begin{itemize}

\item<1-> If you use any filters on your outputs, make sure that they are not too strict to rule out any potentially interesting candidates.
\item<2-> If you are having trouble getting a grammar to load, try adding a blank grammar to the end. The last grammar in a file may behave oddly.
\item<3-> Delete your model file and re-build it if something is refusing to change. Also, make sure that everything made it into the inventory list and \textsc{Con} that you want to have there.
\item<4-> Don't use file extensions on the command line. PyPhon will fill them in as needed.

\item<5-> If you forget the arguments for one of the basic PyPhon scripts, just invoke it with no arguments. It'll tell you.
\item<6-> Let me know if something doesn't work. It might be a bug.
 \end{itemize}
}


\frame{
\frametitle{What is still in the works?}
\begin{itemize}
\item A manual
\item Faster operation
\item Full support for Unicode characters
\item Direct output to \LaTeX
\item A chocolate and wine icebox cake! (Made while compiling this presentation. May not be uploaded to the lab site. May be available in the kitchen at five o'clock.)
\item A cleaner, more consistent interface (maybe even a GUI)
\item A fully functioning, three-tiered model of LPM-OT
\item Whatever you want...
 \end{itemize}
}


\frame{
\frametitle{Thanks!}
Questions and comments:
\begin{itemize}
 \item \href{mailto:sbowman@stanford.edu}{sbowman@stanford.edu}
 \item \url{http://clml.uchicago.edu}

\end{itemize}
}



\frame{
\frametitle{Pretty Graphs!}

\begin{figure}[htp]
\centering
\includegraphics[scale=0.45]{typology-tOrder}
\end{figure}

}



\frame{
\frametitle{Pretty Graphs!}

\begin{figure}[htp]
\centering
\includegraphics[scale=0.45]{OT}
\end{figure}

}

\end{document}